package aip.assignment2.persistence.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Stone
 */
@Entity
@Table(name = "person_name")
@XmlRootElement
@NamedQueries(
{
	@NamedQuery(name = "PersonName.findAll", query = "SELECT p FROM PersonName p"),
	@NamedQuery(name = "PersonName.findById", query = "SELECT p FROM PersonName p WHERE p.id = :id"),
	@NamedQuery(name = "PersonName.findByTitle", query = "SELECT p FROM PersonName p WHERE p.title = :title"),
	@NamedQuery(name = "PersonName.findBySurname", query = "SELECT p FROM PersonName p WHERE p.surname = :surname"),
	@NamedQuery(name = "PersonName.findByGivenName", query = "SELECT p FROM PersonName p WHERE p.givenName = :givenName")
})
public class PersonName implements Serializable
{
	private static final long serialVersionUID = 1L;
	@Id
	@SequenceGenerator(name = "person_name_id", allocationSize = 1, sequenceName = "person_name_id_seq")
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "person_name_id")
	@Basic(optional = false)
	@Column(name = "id")
	private Integer id;
	@JoinColumn(name = "title", referencedColumnName = "id")
	@ManyToOne(optional = false)
	private PersonTitle title;
	@Basic(optional = false)
	@NotNull
	@Size(min = 1, max = 100)
	@Column(name = "surname")
	private String surname;
	@Basic(optional = false)
	@NotNull
	@Size(min = 1, max = 100)
	@Column(name = "given_name")
	private String givenName;
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "name")
	private List<Customer> customerList;
	public PersonName()
	{
	}
	public PersonName(Integer id)
	{
		this.id = id;
	}
	public PersonName(Integer id, String surname, String givenName)
	{
		this.id = id;
		this.surname = surname;
		this.givenName = givenName;
	}
	public Integer getId()
	{
		return id;
	}
	public void setId(Integer id)
	{
		this.id = id;
	}
	public PersonTitle getTitle()
	{
		return title;
	}
	public void setTitle(PersonTitle title)
	{
		this.title = title;
	}
	public String getSurname()
	{
		return surname;
	}
	public void setSurname(String surname)
	{
		this.surname = surname;
	}
	public String getGivenName()
	{
		return givenName;
	}
	public void setGivenName(String givenName)
	{
		this.givenName = givenName;
	}
	@XmlTransient
	public List<Customer> getCustomerList()
	{
		return customerList;
	}
	public void setCustomerList(List<Customer> customerList)
	{
		this.customerList = customerList;
	}
	@Override
	public int hashCode()
	{
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}
	@Override
	public boolean equals(Object object)
	{
		// TODO: Warning - this method won't work in the case the id fields are not set
		if (!(object instanceof PersonName))
		{
			return false;
		}
		PersonName other = (PersonName) object;
		if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id)))
		{
			return false;
		}
		return true;
	}
	@Override
	public String toString()
	{
		return "aip.assignment2.data.entity.PersonName[ id=" + id + " ]";
	}
}
